package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.Scanner;

public class BibliotecaApp {

    public Scanner input = new Scanner(System.in);
    private ArrayList<Item> items = new ArrayList<Item>();

    public void addUserList(User user) {
        this.userList.add(user);
    }

    private ArrayList<User> userList=new ArrayList<User>();
    private Library library ;

    public String userId;



    public BibliotecaApp() {

        userList.add(new User("sumitjas88@gmail.com", "12345", "sumit", 9739927634l, "btm"));
        userList.add(new User("jassumitrocks@gmail.com", "123457","amit", 7376788574l, "kormangala"));
        library = new Library();
    }

    public static void main(String[] args) {
        BibliotecaApp app = new BibliotecaApp();
        String pwd;
        System.out.println("Welcome to Library");
        System.out.println("Enter 'username' and 'password'for menu");
        while (!app.login(app.userId=app.input.next(),pwd=app.input.next())) {
            System.out.println("username or password is incorrect");
        }
        System.out.println("Enter continue for menu");
         while(!"Quit".equals(app.input.next())) {
             System.out.println("Enter 1 for getting List of MoviesLib"+
                     "\nEnter 2 for checked out of movie"+
                     "\nEnter 3 for returning of movie"+
                     "\nEnter 4 for geting user info"+
                     "\nEnter 5 for geting list of books");
             int option = app.input.nextInt();
             switch (option){
                 case 1:
                     System.out.println(app.library.getListofMovies());
                     break;
                 case 2 :
                     System.out.println("Enter the id of item");
                     int itemId =app.input.nextInt();
                     app.library.checkedOut(itemId);
                     break;
                 case 3:
                     System.out.println("Enter the id of item");
                     int id = app.input.nextInt();
                     app.library.returnOfItem(id);
                     break;
                 case 4:
                     app.printUserInformation();
                     break;
                 case 5:
                     System.out.println(app.library.getListOfBooks());
             }
             System.out.println("Enter Quit to exit or Continue to menu");
        }
    }
    private void printUserInformation() {
        User u = getUserById(userId);
        System.out.println(u);
    }
    public User getUserById(String userId) {
        for(User u : userList){
            if(u.getId().equals(userId))
                return u;
        }
        return null;
    }
    public boolean login(String id, String pwd) {
        User u= getUserById(id);
        if(u!=null&&u.isValidpassword(pwd))
            return true;
        return false;
        }


}
